use anyhow::{Context, Result};
use clap::Parser;
//use image::DynamicImage;

mod background;
mod clarity;
mod face;
mod utils;

//#[derive(Parser, Debug)]
//#[command(author, version, about, long_about = None)]
struct Args {
    /// 证件照图片路径
    // #[arg(short, long)]
    image: String,
}

fn main() -> Result<()> {
    //let mut args = Args::parse();
    let image_path = "E:\\研究项目\\Rust\\用Rust和egui 0.32.0写扫雷程序-扣子空间\\id_photo_checker\\target\\debug\\c.jpg";
    //args.image = image_path.to_string();

    // 加载图像
    let img = image::open(image_path).with_context(|| format!("无法加载图像: {}", image_path))?;
    let rgb_img = img.to_rgb8();

    // 执行各项检查
    let mut results = Vec::new();

    // 背景检查
    match background::check_background(&rgb_img) {
        Ok(bg) => results.push(format!("✅ 背景检查: {}", bg)),
        Err(e) => results.push(format!("❌ 背景检查: {}", e)),
    }

    // 人脸检查
    match face::check_face(&rgb_img) {
        Ok(_) => results.push("✅ 人脸检查: 人脸检测及比例正常".to_string()),
        Err(e) => results.push(format!("❌ 人脸检查: {}", e)),
    }

    // 清晰度检查
    match clarity::check_clarity(&img) {
        Ok(score) => results.push(format!("✅ 清晰度检查: 清晰度良好 (评分: {:.2})", score)),
        Err(e) => results.push(format!("❌ 清晰度检查: {}", e)),
    }

    // 输出结果
    println!("证件照检查结果:\n{}", results.join("\n"));

    Ok(())
}
